﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;//Lambda Expression

public partial class _35newpart_Lambda表达式 : System.Web.UI.Page
{



    //teach web site http://www.cnblogs.com/webabcd/archive/2007/10/12/921748.html


    /// <summary>
    /// Lamdba Expression
    /// </summary>
    List<test> list = new List<test>() {
        
        
        new test{ ID=1, Name="webabcd"},
        new test{ID=2, Name="webabcdefg"},
        new test{ID=3,Name="webabcdefgdffdsfsfdsf"}
        };



    protected void Page_Load(object sender, EventArgs e)
    {
        
    /// <summary>
    /// use Lambdam Expression
    /// </summary>
        IEnumerable<test> l = list.Where(le => le.Name == "webabcd");//搜索 Name ="webabcd" 的内容

        foreach (var oo in l)
        {
            Response.Write(oo.Name);
        }

         lenxxx();
    }

    /// <summary>
    /// 执行长度的lambda expression
    /// </summary>
    private void lenxxx()
    {
        IEnumerable < test > l= list.Where(ps => ps.Name.Length >= 10 && ps.Name.Length != 0);
        Response.Write("<br/> ex2:");
        foreach (var oo in l)
        {
            Response.Write(oo.Name);
        }


        ///相当于的from 表达式
        var psu = from ps in list
                  where
                      ps.ID > 2
                      && ps.Name.Length >= 10
                      || ps.Name.Length > 9
                  orderby ps.ID descending
                  select

                      ps;
        Response.Write("<br/> ex3:");
        foreach (var oo in psu)
        {
            Response.Write(oo.Name);
        }

    }
}

public class test
{
    /// <summary>
    /// ID
    /// </summary>
    public int ID { get; set; }

    /// <summary>
    /// 名字
    /// </summary>
    public string Name { get; set; }
}